package com.xianbeiying.app.ckgl.widght;

import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.Color;
import android.os.Build;
import android.util.AttributeSet;
import android.widget.LinearLayout;

import org.achartengine.ChartFactory;
import org.achartengine.GraphicalView;
import org.achartengine.model.CategorySeries;
import org.achartengine.renderer.DefaultRenderer;
import org.achartengine.renderer.SimpleSeriesRenderer;

//自定义扇形园   broken line
public class ChartPieView extends LinearLayout{
//	public static int[] COLORS = new int[] {R.color.pie_analysis_color1, R.color.pie_analysis_color2, R.color.pie_analysis_color3,
//			R.color.pie_analysis_color4, R.color.pie_analysis_color5 };
	private LinearLayout view;
	public ChartPieView(Context context) {
		super(context);
		init(context);
		
	}

	@TargetApi(Build.VERSION_CODES.HONEYCOMB) 
	public ChartPieView(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		init(context);
	}

	public ChartPieView(Context context, AttributeSet attrs) {
		super(context, attrs);
		init(context);
	}

	private void init(Context mContext){
	
	}
	public void  drawChartView(double[] value,String [] descrept,int[] COLORS){
		DrawPie(this, value,descrept,COLORS);
		
	}
	public void DrawPie(LinearLayout layout, double[] value,String [] descrept,int[] COLORS) {
		CategorySeries mSeries = new CategorySeries("");
        DefaultRenderer mRenderer = new DefaultRenderer();
        mRenderer.setLabelsColor(Color.TRANSPARENT);
		mRenderer.setPanEnabled(false);
		mRenderer.setLegendTextSize(14);
		mRenderer.setLegendHeight(5);
		mRenderer.setMargins(new int[]{1, 5, 5, 0});
		GraphicalView mChartView;
		mChartView = ChartFactory.getPieChartView(layout.getContext(), mSeries, mRenderer);
		layout.addView(mChartView, new LayoutParams(LayoutParams.WRAP_CONTENT,
		LayoutParams.WRAP_CONTENT));
		mRenderer.removeAllRenderers();
		mSeries.clear();
		for (double v : value) {
		mSeries.add(descrept[mSeries.getItemCount()] , v);
		SimpleSeriesRenderer renderer = new SimpleSeriesRenderer();
		renderer.setColor(getContext().getResources().getColor(COLORS[(mSeries.getItemCount() - 1)
		% COLORS.length]));
		mRenderer.addSeriesRenderer(renderer);
		}
		mChartView.repaint();
		}
		}
